package cn.tedu.com.control;

import cn.tedu.com.bean.UserInfo;
import cn.tedu.com.service.IQuertUserInfo;
import cn.tedu.com.util.RedisPoolListenerUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
@Slf4j
public class TestControl {
//    @Autowired
//    @Qualifier("rtOne")
//    private RedisTemplate redisTemplate;
    @Autowired
    private IQuertUserInfo queryUserInfoImpl;
    @GetMapping("/hello")
    public String test(){
        RedisTemplate<String,Object> redisTemplate= RedisPoolListenerUtil.getRTDBByKey(RedisPoolListenerUtil.REDIS_REMPLATE_DB1);
        redisTemplate.opsForValue().set("testhello","Hello World");
        String str = (String)redisTemplate.opsForValue().get("testhello");
        System.out.println(str);

        return "Hello World";
    }

    @GetMapping("/userinfos")
    public List<UserInfo> queryUserInfos(){
        List<UserInfo> userInfos = queryUserInfoImpl.queryUserInfos();
        log.info("[TestControl] [test] userInfos={}",userInfos);
        System.out.println("query UserInfo={}"+userInfos);
        return  userInfos;
    }
}
